package com.example.replacebooks.mapper;

import com.example.replacebooks.entity.Orders;
import com.example.replacebooks.entity.Params;
import com.example.replacebooks.entity.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

@Repository
public interface OrderMapper extends Mapper<Orders> {
    List<Orders> findBySearch(@Param("params") Params params,@Param("userid") Integer userid ,@Param("role") Integer role);

    @Select("select * from orders where orderid = #{orderid} limit 1")
    Orders findByOrderid(@Param("orderid") Integer orderid);

    @Update("update orders set userid = #{userid},createtime = #{createtime},bookid = #{bookid},price = #{price},num = #{num},state = #{state} where orderid = #{orderid}")
    void updateByOrderid(Orders orders);

    @Select("select * from orders where bookid = #{bookid} and userid = #{userid}")
    Orders findByBookidAndUserid(Integer bookid, Integer userid);
}

